/**
 * Copyright (c) 2014-2015, Suredy technology Co., Ltd. All rights reserved.
 * 
 * @author ZhangMaoren
 * @since 2015年4月13日
 * @version 0.1
 */
package com.suredy.base.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * @author ZhangMaoren
 *
 */
@Entity
@Table(name = "T_SECURITY_RESOURCE")
public class Resource implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8086832315669302656L;

	@Column(name = "AVAILABLE")
	private Boolean available = Boolean.TRUE; // 是否可用,如不可用则不能授权,但已授权的不会停止使用

	@Column(name = "CREATETIME")
	private Date createTime;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "ID")
	private Long id;

	@Column(name = "LASTMODIFIEDTIME")
	private Date lastModifiedTime;

	@Column(name = "NAME", length = 512)
	private String name;

	@Column(name = "PARENTID")
	private Long parentId;

	@Column(name = "TYPE")
	private Integer type;

	@Column(name = "URL", length = 512)
	private String url;
	
	public Resource(String name, String url, Integer type, Long parentId) {
		this.name = name;
		this.url = url;
		this.type = type;
		this.parentId = parentId;
	}
	
	public Resource(String name, String url, Integer type) {
		this.name = name;
		this.url = url;
		this.type = type;
		this.parentId = 0L;
	}
	
	public Resource(String name, String url, ResourceType type, Long parentId) {
		this.name = name;
		this.url = url;
		this.type = type.ordinal();
		this.parentId = parentId;
	}
	
	public Resource(String name, String url, ResourceType type) {
		this.name = name;
		this.url = url;
		this.type = type.ordinal();
		this.parentId = 0L;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		Resource r = (Resource) o;

		if (id != null ? !id.equals(r.id) : r.id != null) {
			return false;
		}

		if (url != null ? !url.equals(r.url) : r.url != null) {
			return false;
		}
		return true;
	}

	/**
	 * @return the available
	 */
	public Boolean getAvailable() {
		return available;
	}

	/**
	 * @return the createTime
	 */
	public Date getCreateTime() {
		return createTime;
	}

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @return the lastModifiedTime
	 */
	public Date getLastModifiedTime() {
		return lastModifiedTime;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @return the parentId
	 */
	public Long getParentId() {
		return parentId;
	}

	/**
	 * @return the type
	 */
	public Integer getType() {
		return type;
	}

	/**
	 * @return the url
	 */
	public String getUrl() {
		return url;
	}

	@Override
	public int hashCode() {
		return ((id != null ? id.hashCode() : 0) + (url != null ? url.hashCode() : 0));
	}

	/**
	 * @param available the available to set
	 */
	public void setAvailable(Boolean available) {
		this.available = available;
	}

	/**
	 * @param createTime the createTime to set
	 */
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @param lastModifiedTime the lastModifiedTime to set
	 */
	public void setLastModifiedTime(Date lastModifiedTime) {
		this.lastModifiedTime = lastModifiedTime;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @param parentId the parentId to set
	 */
	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(Integer type) {
		this.type = type;
	}

	/**
	 * @param url the url to set
	 */
	public void setUrl(String url) {
		this.url = url;
	}

	@Override
	public String toString() {
		return "Resource[" + "id=" + id + ", name='" + name + "\'" + ", url='" + url + "\'" + "]";
	}
}
